using System;
using JetBrains.Metadata.Reader.API;
using JetBrains.ReSharper.Psi;

namespace JamesKovacs.ReSharper.UnitTestSupport.VstsUnit {
    class VstsUnitTestInspector {
        private static readonly CLRTypeName TestClassAttribute = new CLRTypeName("Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute");
        private static readonly CLRTypeName TestMethodAttribute = new CLRTypeName("Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute");
        private static readonly CLRTypeName IgnoreAttribute = new CLRTypeName("Microsoft.VisualStudio.TestTools.UnitTesting.gnoreAttribute");

        public static bool IsTestFixture(IMetadataTypeInfo typeInfo) {
            if(typeInfo == null) {
                throw new ArgumentNullException("typeInfo");
            }
            return typeInfo.HasCustomAttribute(TestClassAttribute.ClrName);
        }

        public static bool IsTestFixture(ITypeElement element) {
            if(element == null) {
                throw new ArgumentNullException("element");
            }
            return element.HasAttributeInstance(TestClassAttribute, false);
        }

        public static bool IsTestMethod(IMetadataMethod method) {
            if(method == null) {
                throw new ArgumentNullException("method");
            }
            return method.HasCustomAttribute(TestMethodAttribute.ClrName);
        }

        public static bool IsTestMethod(ITypeMember method) {
            if(method == null) {
                throw new ArgumentNullException("method");
            }
            return method.HasAttributeInstance(TestMethodAttribute, false);
        }

        public static bool IsIgnored(IMetadataEntity typeInfo) {
            return typeInfo.HasCustomAttribute(IgnoreAttribute.ClrName);
        }
    }
}